import {
  showToast
} from "../utils/util.js"
export const login = () => {
  return new Promise((resolve, reject) => {
    uni.login({
      timeout: 10000,
      success: (result) => {
        resolve(result);
      },
      fail: (err) => {
        reject(err);
      }
    });
  })
}

/**
 * promise 形式的 小程序的微信支付
 * @param {object} pay 支付所必要的参数
 */
export const requestPayment = (pay) => {
  return new Promise((resolve, reject) => {
    console.log(pay);
    uni.requestPayment({
      ...pay,
      success: (result) => {
        resolve(result)
      },
      fail: (err) => {
        console.log(err);
        showToast({
          title: "支付参数错误"
        })
      }
    });

  })
}
